package job.sm;

import java.util.*;

/**
 * Author: Zhang Dongwei
 * Date: 2023/8/7 11:35
 */
public class dj {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int res;
        int cropField_rows = 0;
        int cropField_cols = 0;
        cropField_rows = in.nextInt();
        cropField_cols = in.nextInt();
        int[][] cropField = new int[cropField_rows][cropField_cols];
        for (int cropField_i = 0; cropField_i < cropField_rows; cropField_i++) {
            for (int cropField_j = 0; cropField_j < cropField_cols; cropField_j++) {
                cropField[cropField_i][cropField_j] = in.nextInt();
            }
        }
        if (in.hasNextLine()) {
            in.nextLine();
        }
        res = new Solution1().calculateMaxTotalYie(cropField);
        System.out.println(String.valueOf(res));
    }
}

class Solution1 {
    public int calculateMaxTotalYie(int[][] cropField) {
        int[] sumrow = new int[cropField.length];
        int[] sumcol = new int[cropField[0].length];
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < cropField.length; i++) {
            for (int j = 0; j < cropField[0].length; j++) {
                sumrow[i] += cropField[i][j];
            }
        }
        System.out.println(Arrays.toString(sumrow));
        for (int i = 0; i < cropField[0].length; i++) {
            for (int j = 0; j < cropField.length; j++) {
                sumcol[i] += cropField[j][i];
            }
        }
        System.out.println(Arrays.toString(sumcol));
        int total = 0;
        for (int i = 0; i < cropField.length; i++) {
            for (int j = 0; j < cropField[0].length; j++) {
                total += cropField[i][j];
            }
        }
        System.out.println(total);
        for (int i = 0; i < cropField.length; i++) {
            for (int j = 0; j < cropField[0].length; j++) {
                System.out.println(total + (sumrow[i] + sumcol[j]) * 2 - sumcol[j] - sumrow[i] - cropField[i][j] + "***" + i + j);
                if ((total + (sumrow[i] + sumcol[j]) * 2 - sumcol[j] - sumrow[i] - cropField[i][j]) > max) {
                    max = total + (sumrow[i] + sumcol[j]) * 2 - sumcol[j] - sumrow[i] - cropField[i][j];
                }
            }
        }
        return max;
    }
}
